{
LANG : PASCAL
PROB : heritage
}

program HERITAGE;
const
  fi = 'heritage.in';
  fo = 'heritage.out';
type
  tree = string[26];
var
  in_order, pre_order, post_order : tree;

procedure visit(in_t, pre_t : tree);
var
  in_left, in_right, pre_left, pre_right : tree;
  root : char;
  i, c, l : integer;
begin
  l := length(in_t);
  if l = 0 then exit;
  if l = 1 then
  begin
    post_order := post_order + in_t;
    exit;
  end;
  root := pre_t[1];

  c := pos(root, in_t);
  in_left := copy(in_t, 1, c-1);
  in_right := copy(in_t, c+1, l-c);

  pre_left  := '';
  pre_right := '';
  for i := 2 to l do
    if pos(pre_t[i], in_t) < c then pre_left := pre_left + pre_t[i]
    else pre_right := pre_right + pre_t[i];

  visit(in_left, pre_left);
  visit(in_right, pre_right);
  visit(root, root);
end;

begin
  assign(input, fi); reset(input);
  assign(output, fo); rewrite(output);
  readln(in_order);
  readln(pre_order);
  visit(in_order, pre_order);
  writeln(post_order);
  close(output);
  close(input);
end.